package com.xbongbong.parent.interfaces;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.pojo.AddValidateReturnPojo;
import com.xbongbong.pro.formdata.pojo.SaasNeedRedundantAttrPojo;
import com.xbongbong.pro.formdata.pojo.SaveFormExplainPojo;
import com.xbongbong.pro.formdata.pojo.vo.BeforeSaveVO;

import java.util.List;
import java.util.Map;

/**
 * @author 吴峰
 * @date 2021/12/28 16:11
 */
public interface BusinessAddBeforeService<F, T> {


    /**
     * 新建权限的校验以及数据量的校验
     * com.xbongbong.paas.service.AbstractFormDataService#validatePermission(com.xbongbong.paas.pojo.dto.FormDataAddDTO)
     * @param formDataAddDTO
     * @throws XbbException
     */
    void validatePermission(FormDataAddDTO formDataAddDTO) throws XbbException;
    /**
     * 将分为公用部分和预收款，预付款，工作报告分开
     * 预收款，预付款，工作报告请在业务层实现类实现
     * @param formId 表单id
     * @param corpid 公司id
     * @return
     * @throws XbbException
     */
    F getFormEntity(FormDataAddDTO formDataAddDTO) throws XbbException;

    /**
     * 获取字段解释
     * @param corpid
     * @param formId
     * @return
     * @throws XbbException
     */
    SaveFormExplainPojo getExplainMap(Long formId, String corpid) throws XbbException;

    /**
     * 流程可见设置
     * @param paasFormEntityExt
     * @param formDataSaveDTO
     * @param explainMap
     * @return
     * @throws XbbException
     */
    Map<String, FieldAttrEntity> processSetVisible(F paasFormEntityExt, FormDataAddDTO formDataSaveDTO, Map<String, FieldAttrEntity> explainMap) throws XbbException;

    /**
     * 导入的流程可见设置
     * @param paasFormEntityExt
     * @param formDataSaveDTO
     * @param explainMap
     * @return
     * @throws XbbException
     */
    Map<String, FieldAttrEntity> importProcessSetVisible(F paasFormEntityExt, FormDataAddDTO formDataSaveDTO, Map<String, FieldAttrEntity> explainMap) throws XbbException;
    /**
     * 各个业务层的解析数据，目前都封装在接口SaasValidateAnalyticalService
     * @param validateDataDTO
     * @param explainMap
     * @return
     * @throws XbbException
     */
    AddValidateReturnPojo analyticalData(FormDataAddDTO formDataAddDTO, ValidateDataDTO validateDataDTO, Map<String, FieldAttrEntity> explainMap) throws XbbException;

    /**
     * 获取实体拼装
     * @param formDataSaveDTO
     * @param paasFormEntityExt
     * @param explainMap
     * @param department
     * @param data
     * @return
     * @throws XbbException
     */
    T getFormData(FormDataAddDTO formDataSaveDTO, F paasFormEntityExt, Map<String, FieldAttrEntity> explainMap, Long department, JSONObject data) throws XbbException;

    /**
     * 开始审批流或者工作流
     * @param paasFormDataEntity
     * @param paasFormEntityExt
     * @param saasNeedRedundantAttrPojo
     * @param formDataAddDTO
     * @param explainMap
     * @param explainList
     * @return
     * @throws XbbException
     */
    BeforeSaveVO startWorkflowOrProcess(T paasFormDataEntity, F paasFormEntityExt, SaasNeedRedundantAttrPojo saasNeedRedundantAttrPojo, FormDataAddDTO formDataAddDTO, Map<String, FieldAttrEntity> explainMap, List<FieldAttrEntity> explainList) throws XbbException;

    /**
     * 开始工作流
     * @param formDataSaveDTO
     * @param beforeSaveVO
     * @param paasFormDataEntity
     * @return
     * @throws XbbException
     */
    boolean isEnableNewWorkflow(FormDataAddDTO formDataSaveDTO, BeforeSaveVO beforeSaveVO, T paasFormDataEntity) throws XbbException;


    /**
     * 开始审批流，导入调用
     * @param paasFormDataEntity
     * @param paasFormEntityExt
     * @param saasNeedRedundantAttrPojo
     * @param formDataAddDTO
     * @param explainMap
     * @param explainList
     * @return com.xbongbong.pro.formdata.pojo.vo.BeforeSaveVO
     * @author 吴峰
     * @date 2022/1/10 15:35
     * @throws XbbException
     */
    BeforeSaveVO startWorkFlow(T paasFormDataEntity, F paasFormEntityExt, SaasNeedRedundantAttrPojo saasNeedRedundantAttrPojo, FormDataAddDTO formDataAddDTO, Map<String, FieldAttrEntity> explainMap, List<FieldAttrEntity> explainList) throws XbbException;
    /**
     * 开始审批流
     * @param formDataAddDTO
     * @param beforeSaveVO
     * @return  java.lang.Integer 1：无需审批，后面需要进行插入操作 非1：进入审批，后面不需要进行插入操作
     * @throws XbbException
     */
    Integer startProcess(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO) throws XbbException;

    /**
     * 工作流发送消息
     * @param formDataAddDTO
     * @param beforeSaveVO
     * @param formDataSaveVO
     * @throws XbbException
     */
    void workflowAddTrigger(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO, FormDataAddVO formDataSaveVO) throws XbbException;
}
